'use strict';
const express = require('express'),
    bodyParser = require('body-parser'),
    session=require("express-session"),
    path = require('path'),
    passport = require('passport'),
    favicon = require('serve-favicon'),
    staticRoute = require('./static_router'),
    router = require('./router'),
    cookieParser = require('cookie-parser'),
    Router = express.Router();


module.exports = function(app){
    var app = app || express();
    app.use(passport.initialize());
    app.use(passport.session());
    app.use(session({
        secret: 'secret',
        cookie:{
            maxAge: 1000*60*30
        }
    }));
    app.use(cookieParser());
    app.use(Router);
    Router.use(favicon(path.join(__dirname, '../../client/views', 'favicon.ico')));
    Router.use(bodyParser.json());
    Router.use(bodyParser.urlencoded({ extended: false }));
    staticRoute(Router);
    router(Router);

    return app;
};